{include file="public/header" /}


<div class="x-body">

  <xblock>
    <!-- <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button> -->
    <button class="layui-btn  layui-btn-sm" onclick="model_add(1)"><i class="layui-icon"></i>添加</button>
    <span class="x-right" style="line-height:40px">共有数据：{$count.count} 条</span>
  </xblock>
  <table class="layui-table">
    <thead>
      <tr>
        <th>
          <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
        </th>
        <th>ID</th>
        <th>菜单名称</th>
        <th>控制器名称</th>
        <th>方法名称</th>
        <th>icon</th>
        <th>排序</th>
        <th>pid</th>
        <th>状态</th>
        <th>操作</th>
    </thead>
    <tbody>
      {foreach name="list" item="v" key="k" }
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
          </td>
          <td>{$v.id}</td>
          <td>{$v.name}</td>
          <td>{$v.controller}</td>
          <td>{$v.action}</td>
          <td><i class="iconfont">{$v.icon}</i></td>
          <td>{$v.rank}</td>
          <td class="td-status">{$v.pid}</td>
          <td class="td-status">
            {if condition=" $v.status == '0' "}
              <span class="layui-badge-dot"></span> 不显示
            {else /}
              <span class="layui-badge-dot layui-bg-green"></span> 显示
            {/if}
           
          </td>
          <td class="td-manage">
            <a title="编辑"  onclick="model_add(2,'{$v.id}','{$v.name}','{$v.pid}','{$v.controller}','{$v.action}','{$v.icon}','{$v.rank}','{$v.status}')" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
            <a title="删除" onclick="del({$v.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
          </td>
        </tr>


        {foreach name="v['data']" item="vv" key="kk" }
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$vv.id}</td>
            <td> &emsp;|—— {$vv.name}</td>
            <td>{$vv.controller}</td>
            <td>{$vv.action}</td>
            <td><i class="iconfont">{$vv.icon}</i></td>
            <td>{$vv.rank}</td>
            <td class="td-status">{$vv.pid}</td>
            <td class="td-status">
              {if condition=" $vv.status == '0' "}
                <span class="layui-badge-dot"></span> 不显示
              {else /}
                <span class="layui-badge-dot layui-bg-green"></span> 显示
              {/if}
            </td>
            <td class="td-manage">
              <a title="编辑"  onclick="model_add(2,'{$vv.id}','{$vv.name}','{$vv.pid}','{$vv.controller}','{$vv.action}','{$vv.icon}','{$vv.rank}','{$vv.status}')" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
              <a title="删除" onclick="del({$vv.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
            </td>
          </tr>
          
          {if condition=" $vv.data2 != '' "}
          
          
          {foreach name="vv['data2']" item="vvv" key="kkk" }
            <tr>
              <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
              </td>
              <td>{$vvv.id}</td>
              <td> &emsp;&emsp;&emsp;|—— {$vvv.name}</td>
              <td>{$vvv.controller}</td>
              <td>{$vvv.action}</td>
              <td><i class="iconfont">{$vvv.icon}</i></td>
              <td>{$vvv.rank}</td>
              <td class="td-status">{$vvv.pid}</td>
              <td class="td-status">
                {if condition=" $vvv.status == '0' "}
                  <span class="layui-badge-dot"></span> 不显示
                {else /}
                  <span class="layui-badge-dot layui-bg-green"></span> 显示
                {/if}
              </td>
              <td class="td-manage">
                <a title="编辑"  onclick="model_add(2,'{$vvv.id}','{$vvv.name}','{$vvv.pid}','{$vvv.controller}','{$vvv.action}','{$vvv.icon}','{$vvv.rank}','{$vvv.status}')" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
                <a title="删除" onclick="del({$vvv.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
              </td>
            </tr>
          {/foreach}
          
          {/if}

        {/foreach}

      {/foreach}
    </tbody>
  </table>

</div>

<!-- --------------------js--------------------- -->

<script>

  //模态窗
  function model_add (type,id,name,pid,controller,action,icon,rank,status) {
    if(type == 1){
      var txt = '添加'; 
    }else{
      var txt = '编辑'; 

    }
    layui.use(['layer','form'], function() {
      var form = layui.form;    //渲染
      var layer = layui.layer; //唤起模态窗

      layer.open({
        type: 1,
        title: txt,
        area: ['500px', '500px'] ,
        shadeClose: true,
        content: $('#box').html()
      })
      $('#id').val(id);
      $('#name').val(name);
      $('#pid').val(pid);
      $('#controller').val(controller);
      $('#action').val(action);
      // $('#icon').val('<i class="iconfont">'+icon+'</i>');
      $('#rank').val(rank);
      $(":radio[name='status'][value="+status+"]").attr("checked","checked");  

      form.render();//渲染
    })
  }


//确定-提交
function sub(){

  var name = $('#name').val();
  if(name == ''){
      layer.msg('菜单名不能为空',{
        time:900,           //时间
      });
      return false;
  }
  
  $.ajax({
      type:"get", 
      url:"__APP__/admin/Menu/add_edit",
      data:$(".layui-form").serialize(),

      success:function(data){
        // alert(data);
        returnInfo(data);

      }        
  })//ajax结束
}

function del(id){
  layui.use('layer', function(){
    var layer = layui.layer;
    layer.open({
      title: '询问框'
      ,content: '确定删除这个管理员吗？'
      ,offset: '100px'   
      ,yes: function(index, layer){
          $.ajax({
            type:"post",
            url:"__APP__/admin/Menu/del",
            data:'id='+id,
            dataType:"json",//服务器返回类型
            success:function(data){
                // alert(data);
                 returnInfo(data);
            }
          })
      }
    })
  }); 
}

  
</script>


{include file="public/footer" /}


<!-- --------------------弹窗--------------------- -->

<script id="box">
        <style type="text/css">
        .layui-word-aux{
          font-size:12px;
        }
        </style>
        <form class="layui-form">
        <input type="hidden" id="id" name="id" value='' class="layui-input">
          <div class="layui-form-item" style="margin-top:20px">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>菜单名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name"  class="layui-input">
              </div>
          </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                  <span class="x-red">*</span>选择分级
              </label>
              <div class="layui-input-inline">
                <select name="pid" id="pid" lay-verify="required">
                  
                  <option value="0">--顶级菜单--</option>
                  {foreach name="fenji_list" item="v" key="k" }
                  <option value="{$v.id}">{$v.name}</option>
                  {/foreach}
                
                </select>
              </div>
              <div class="layui-form-mid layui-word-aux">
                  控制器为空是分级选项
              </div>
          </div>

          <div class="layui-form-item">
              <label class="layui-form-label">
                  控制器名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="controller" name="controller" required="" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  非跳转不填
              </div>
          </div>

          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  方法名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="action" name="action" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  同上(显示初始页固定为index)
              </div>
          </div>


          <div class="layui-form-item">
              <label class="layui-form-label">
                icon 
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="icon" name="icon"  class="layui-input" >
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <a target="view_window" href="__APP__/admin/Admin/icon.html">查看字体图标</a>
              </div>
          </div>

          <div class="layui-form-item">
              <label  class="layui-form-label">
                  排序
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="rank" name="rank"  class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  数字越大越靠前
              </div>
          </div>

          

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                是否显示
              </label>
              
              <div class="layui-input-block">
                <input type="radio" name="status" id='status' value="1" title="显示" checked="">
                <input type="radio" name="status" id='status' value="0" title="不显示">
                
              </div>
          </div>
          <hr/>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>

              <a  class="layui-btn" onclick="sub()">
                  提交
              </a>
          </div>
      </form>
</script>